package system;

import java.util.Iterator;
import java.util.List;
import java.util.Scanner;

import user.User;
import voice.VoiceMessageIdentification;

public class MainVoiceMessageTest {

	static SystemFacade facade = SystemFacade.getInstance();
	
	public static void printMessages(List<VoiceMessageIdentification> messages){
		Iterator<VoiceMessageIdentification> msgIt = messages.iterator();
		VoiceMessageIdentification current;
		int value = 0;
		while (msgIt.hasNext()){
			current = msgIt.next();
			System.out.println(value + ": " + current.getFrom() + " " + current.getDate() + " " + current.getTime());
			value++;
		}
	}

	public static void main(String[] args) throws Exception {
		facade
				.criarUsuario("user1", "jose", "email@email.com", "abcdefg",
						"3333");
		facade.criarUsuario("user2", "maria", "email2@email.com", "abcdefg",
				"3333");
		facade.login("user2", "abcdefg", "180.200.200.50");
		facade.enviarConvite("user1", "email2@email.com");
		facade.login("user1", "abcdefg", "200.0.0.1");
		facade.confirmarCompartilhamento("user2", "user1", User.EXIBIR);
		//facade.carregarSistema();
		
		Scanner sc = new Scanner(System.in);
		String word = "";
		String from="";
		String to="";
		while (!word.equals("3")){
			System.out.println("1 - Gravar mensagem");
			System.out.println("2 - Ouvir mensagem");
			System.out.println("3 - Sair");
			word = sc.nextLine();
			if (word.equals("1")){
				System.out.print("De: ");
				from = sc.nextLine();
				System.out.print("Para: ");
				to = sc.nextLine();
				facade.sendVoiceMessage(from, to);
				facade.encerrarSistema();
			} else if (word.equals("2")){
				System.out.print("De: ");
				from = sc.nextLine();
				printMessages(facade.getVoiceMessages(from));
				System.out.print("Digite o indice da mensagem: ");
				to = sc.nextLine();
				facade.playMessage(facade.getMessageId(from, Integer.parseInt(to)));
			} else if (word.equals("3")){
				break;
			}
			
		}
		
	}

}
